<?php 
if (!isset($_POST['keyword'])) {
	exit();
}

require_once ('../conf/pdoConnect.php');
require_once ('./check.php');

$uid = $_SESSION['uid'];
$uid = intval($_SESSION['uid']);

$key = $_POST['keyword'];

$mailList = searchMail($db, $key, $uid);
$count = 0;
if ($mailList) {
	$count = count($mailList);
}

$now = "搜索结果";

function searchMail($db, $key, $uid) 
{
	$sql = "select * from sendMail where `mailTitle` like ? and `belongId` = ? order by `sendTime` desc";
	$stmt = $db->prepare($sql);
	$exec = $stmt->execute(array("%$key%", $uid));

	if ($exec) {
		//var_dump($stmt->fetchAll());
		$mailList = $stmt->fetchAll();
		return $mailList;
	}
}

require_once ('../mailList.php');
$db = null;